package com.ruoyi.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.ruoyi.system.domain.SmsHomeAdvertise;
import com.ruoyi.system.mapper.SmsHomeAdvertiseMapper;
import com.ruoyi.system.service.ISmsHomeAdvertiseService;

/**
 * <p>
 * 首页轮播广告表 服务实现类
 * </p>
 *
 * @author flowr
 * @since 2019-04-19
 */
@Service
public class SmsHomeAdvertiseServiceImpl extends ServiceImpl<SmsHomeAdvertiseMapper, SmsHomeAdvertise> implements ISmsHomeAdvertiseService {
    @Resource
    private SmsHomeAdvertiseMapper homeAdvertiseMapper;

    @Override
	public boolean save(SmsHomeAdvertise entity) {
    	int count = homeAdvertiseMapper.insert(entity);
    	if(count > 0){
    		return true;
    	}
		return false;
	}
    
    @Override
	public boolean removeById(Long id) {
    	int count = homeAdvertiseMapper.deleteById(id);
    	if(count > 0){
    		return true;
    	}
		return false;
	}
    
    @Override
	public boolean updateById(SmsHomeAdvertise entity) {
    	int count = homeAdvertiseMapper.updateById(entity);
    	if(count > 0){
    		return true;
    	}
		return false;
	}

	@Override
	public Object page(Page<SmsHomeAdvertise> page, QueryWrapper<SmsHomeAdvertise> queryWrapper) {
		List<SmsHomeAdvertise> list = homeAdvertiseMapper.selectList(queryWrapper);
		 PageInfo<SmsHomeAdvertise> pageInfo = new PageInfo<SmsHomeAdvertise>(list);
		return pageInfo;
	}
    
    @Override
    public int updateSort(Long id, Integer sort) {
    	SmsHomeAdvertise homeNewProduct = homeAdvertiseMapper.selectById(id);
        homeNewProduct.setSort(sort);
        return homeAdvertiseMapper.updateById(homeNewProduct);
    }

    @Override
    public int updateRecommendStatus(List<Long> ids, Integer recommendStatus) {
    	SmsHomeAdvertise record = new SmsHomeAdvertise();
	        return homeAdvertiseMapper.update(record, new QueryWrapper<SmsHomeAdvertise>().in("id", ids));
    }

	@Override
	public SmsHomeAdvertise getById(Long id) {
		System.out.println("aa");
		return homeAdvertiseMapper.selectById(id);
	}

	@Override
	public boolean removeByIds(List<Long> ids) {
		int count = homeAdvertiseMapper.deleteBatchIds(ids);
		if(count > 0){
    		return true;
    	}
		return false;
	}

}
